<?php
	
	 error_reporting(E_ALL);
?>
 
<script>
 

function printData(){
window.print();
}
	
	function reloadPage(){	
		var department_id =$("#department_id").val();		
		var karyawan_id =$("#karyawan_id").val();	
		var tahun_ajaran_id =$("#tahun_ajaran_id").val();	
		var kelas_id =$("#kelas_id").val();											
		var absent_date =$("#absent_date").val();	
		var absent_date_end =$("#absent_date_end").val();					
		$("#tblData").jqGrid("setGridParam",{postData:{"kelas_tahun_ajaran_id" :$("#kelas_tahun_ajaran_id").val(),"absent_date" :$("#absent_date").val(),"absent_date_end" :$("#absent_date_end").val(),"tahun_ajaran_id" :$("#tahun_ajaran_id").val()},datatype:"json"}).trigger("reloadGrid",[{current:true}]);
		//$("#tblData").jqGrid("setGridParam",{postData:{"karyawan_id" :$("#karyawan_id").val()},datatype:"json"}).trigger("reloadGrid",[{current:true}]);		
		//$("#idSrcTblData").val("");
	//	 alert("semester_id" +$("#semester_id").val()+"pelajaran_id" +$("#pelajaran_id").val()+"kelas_tahun_ajaran_id" +$("#kelas_tahun_ajaran_id").val()+"task_pelajaran_id" +$("#task_pelajaran_id").val()+"tahun_ajaran_id" +$("#tahun_ajaran_id").val()+"task_pelajaran_detail_id" +$("#task_pelajaran_detail_id").val());
	} 
	  
$(function(){
		var department_id =$("#department_id").val();		
		var karyawan_id =$("#karyawan_id").val();	
		var tahun_ajaran_id =$("#tahun_ajaran_id").val();	
		var semester_id =$("#semester_id").val();	
		var pelajaran_id =$("#pelajaran_id").val();	
		var kelas_tahun_ajaran_id =$("#kelas_tahun_ajaran_id").val();											
		var task_pelajaran_id =$("#task_pelajaran_id").val();	
		var task_pelajaran_detail_id =$("#task_pelajaran_detail_id").val();		
		var absent_date =$("#absent_date").val();					
		var absent_date_end =$("#absent_date_end").val();									
		var numberTemplate = {formatter: 'number', align: 'right', sorttype: 'number'};	 
		$("#tblData").jqGrid({
			url:'index.php?r=akademik/presensi/report_presensi/ByMonthList',
			postData:{"department_id":department_id,"karyawan_id" :karyawan_id,"tahun_ajaran_id":tahun_ajaran_id,"semester_id" :semester_id,"pelajaran_id":pelajaran_id,"kelas_tahun_ajaran_id" :kelas_tahun_ajaran_id,"task_pelajaran_id" :task_pelajaran_id,"task_pelajaran_detail_id" :task_pelajaran_detail_id,"absent_date":absent_date,"absent_date_end":absent_date_end},
			datatype: 'json',
			loadonce:true,
			mtype:"GET",
			autowidth:true,
			height:"100%",
			altRows:true,
			ignoreCase:true,
			colNames: ['Absent Date','Student ID','Student Name',  'Status','notes'],
			colModel: [
				{name: 'absent_date', index: 'absent_date', formatter : 'date', formatoptions : {newformat : 'd M Y'},width: 50 },				 
				{name: 'sid', index: 'sid', width: 60 },				 				
				{name: 'name', index: 'name', width: 140,search:true},
				{name: 'presensi_status', index: 'presensi_status', width: 50,search:true},				
				{name: 'notes', index: 'notes'},
				
			],
			gridview: true,
			rownumbers: false,
			rowNum: 10,
			rowList: [5, 10, 15],
			pager: '#navTblData',
			viewrecords: true,
			caption: 'Presensi Student By Month',
			jsonReader : { 
				root:"model",
				repeatitems: false			
			},
			loadComplete:function(data){
				console.log(data);
			}
		});
		$("#tblData").jqGrid('navGrid','#navTblData',{add:false,edit:false,search:false,del:false,refresh:false});
		
		//add search text
		$("#tblData").jqGrid('addSearchText',["name","presensi_status"]);
//		$('#absent_date').monthpicker({pattern:"yyyy-mm"});
//		$('#absent_date_end').monthpicker({pattern:"yyyy-mm"});		
	});
 
 
</script>
	<script>
	 
function Department_OnChange_fill_all(){ 
	window.parent.showLoader();	
		$filter = {"is_active":1,"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"tahun_ajaran_id",title_field:"tahun_ajaran_name",group:"tahun_ajaran_id"},
			success: function(data) {
				printConsole(data);
				fillSelectData("#tahun_ajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		
					
	
		$filter = {"is_active":1,"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"tingkatan_id",title_field:"tingkatan_name",group:"tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#tingkatan_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});		
				
		$filter = {"is_active":1,"tingkatan_id":$("#tingkatan_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"kelas_tahun_ajaran_id",title_field:"kelas_name",group:"kelas_id,tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#kelas_tahun_ajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		$filter = {"is_active":1,"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"MPresensi",filter: $filter,value_field:"absent_date",title_field:"absent_date"  },
			success: function(data) {
				var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
				var datenow = Date.parse(data[0].title);
				var dateset = datenow.getDate()+1 + '-' + monthNames[datenow.getMonth()] + '-'+ datenow.getFullYear(); 							
				$("#absent_date").val(dateset);
				reloadPage();	
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});			  					 
}	

function Tahun_Ajaran_OnChange_fill_all(){ 
	window.parent.showLoader();	
 		$filter = {"is_active":1,"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"tingkatan_id",title_field:"tingkatan_name",group:"tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#tingkatan_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});		
				
		$filter = {"is_active":1,"tingkatan_id":$("#tingkatan_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"kelas_tahun_ajaran_id",title_field:"kelas_name",group:"kelas_id,tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#kelas_tahun_ajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		$filter = {"is_active":1,"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"MPresensi",filter: $filter,value_field:"absent_date",title_field:"absent_date"  },
			success: function(data) {
				var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
				var datenow = Date.parse(data[0].title);
				var dateset = datenow.getDate()+1 + '-' + monthNames[datenow.getMonth()] + '-'+ datenow.getFullYear(); 								
				$("#absent_date").val(dateset);
				reloadPage();	
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});			 					 
}			
 
function Tingkatan_OnChange_fill_Task_Detail(){ 
	window.parent.showLoader();	
		$filter = {"is_active":1,"tingkatan_id":$("#tingkatan_id").val(),"tahun_ajaran_id":$("#tahun_ajaran_id").val(),"department_id":$("#department_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"VJadwalPelajaranKelasTahunAjaran",filter: $filter,value_field:"kelas_tahun_ajaran_id",title_field:"kelas_name",group:"kelas_id,tingkatan_id" },
			success: function(data) {
				printConsole(data);
				fillSelectData("#kelas_tahun_ajaran_id",data);	
				reloadPage();
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		$filter = {"is_active":1,"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"MPresensi",filter: $filter,value_field:"absent_date",title_field:"absent_date"  },
			success: function(data) {
				var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
				var datenow = Date.parse(data[0].title);
				var dateset = datenow.getDate()+1 + '-' + monthNames[datenow.getMonth()] + '-'+ datenow.getFullYear(); 					
				$("#absent_date").val(dateset);
				reloadPage();	
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});			 
	 					 
}		
 
function Kelas_OnChange_fill_Kalender(){ 

	window.parent.showLoader();	
		$filter = {"is_active":1,"kelas_tahun_ajaran_id":$("#kelas_tahun_ajaran_id").val()};
		$.ajax({	
			url : "index.php?r=Data_select/selectDataAjxResult",
			type:"GET",
			async:false,
			//data: {filter: "is_active=true and department_id = '" + $("#department_id").val() + "' union select id,name,1,1,null,null,1,1,1 from m_kelas" },
			data: {obj:"MPresensi",filter: $filter,value_field:"absent_date",title_field:"absent_date"  },
			success: function(data) {
				var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
				var datenow = Date.parse(data[0].title);
				//var dateset = datenow.getDate()+1 + '-' + monthNames[datenow.getMonth()] + '-'+ datenow.getFullYear(); 			
				var dateset = datenow.getDate()+1 + '-' + monthNames[datenow.getMonth()] + '-'+ datenow.getFullYear(); 						
				$("#absent_date").val(dateset);
				reloadPage();	
			},
			complete:function(){
				window.parent.hideLoader();
			}
		});	
		 
	 					 
} 
 
  
 
 
 
</script>
 

<div>
    <?php 
	/*
		$this->widget('application.components.widgets.TextField', 
			array("name"=>"karyawan_name",
				"value"=>$karyawan_name,
				"htmlOptions"=>"size='20'",
				"htmlOptions"=>"disabled",				
				"label"=>array(
					"value"=>Yii::t("label","Guru"),
					"htmlOptions"=>"class='form' style='width:100px;'"
				)
			)
		);		
		*/
    ?>		
    <input type="hidden" id="karyawan_id" name="karyawan_id" value="<?php echo $karyawan_id ?>"  />
    <input type="hidden" id="karyawan_name" name="karyawan_name" value="<?php echo $karyawan_name ?>"  />

 
</div>    
 

  
<div style="float:rigth">&nbsp;
<?php 
    $this->widget('application.components.widgets.ActionBar', 
        array("menuAlign" => "right", 
            'items' => array(
                array(
                    'id' => "btnRefresh",
                    'title' => Yii::t("menu","Segarkan"),
                    'icon' => "images/action/Action-Refresh-icon.png",
                    'callback'=>"reloadPage"
                ),	 /*			
                array(
                    'id' => "btnNew",
                    'title' => Yii::t("menu","Absent"),
                    'icon' => "images/action/Actions-document-new-icon.png",
                    'callback'=>"newData"
                ), */ 
                array(
                    'id' => "btnNew",
                    'title' => Yii::t("menu","Cetak"),
                    'icon' => "images/action/Actions-document-print-icon2.png",
                    'callback'=>"printData"
                ),					
                 
            ) 
        )
    );
?>
</div>	
 
 	<div style="clear:both"></div>	
<div style="float:left;width:22%;">
 <div>
 		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Department") ?></label>	
		<select name="department_id" id="department_id" onchange="Department_OnChange_fill_all()"   >
			<?php
				foreach ($departments as $department){
					$selected = $department_id == $department["department_id"] ? "selected" : "";				
					echo"<option value='$department[department_id]' $selected  >$department[department_id]</option>";
				}
			?>
		</select> 
</div>        
	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Tahun Ajaran") ?></label>	
		<select name="tahun_ajaran_id" id="tahun_ajaran_id" onChange="Tahun_Ajaran_OnChange_fill_all()">
			<?php
				foreach ($tahunAjarans as $tahunAjaran){
					$selected = $tahun_ajaran_id == $tahunAjaran["tahun_ajaran_id"] ? "selected" : "";				
					echo"<option value='$tahunAjaran[tahun_ajaran_id]' $selected>$tahunAjaran[tahun_ajaran_name]</option>";
				}
			?>
		</select>
	</div>
 
 	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Tingkatan") ?></label>	
		<select name="tingkatan_id" id="tingkatan_id"   onchange="Tingkatan_OnChange_fill_Task_Detail()"  >
			<?php
				foreach ($tingkatans as $tingkatan){
					$selected = $tingkatan_id == $tingkatan["tingkatan_id"] ? "selected" : "";				
					echo"<option value='$tingkatan[tingkatan_id]' $selected>$tingkatan[tingkatan_name]</option>";
				}
			?>
		</select>
	</div>       
           
  	<div>
		<label class="form mandatory" style="width:100px"><?php echo Yii::t("label", "Kelas") ?></label>	
		<select name="kelas_tahun_ajaran_id" id="kelas_tahun_ajaran_id"   onchange="Kelas_OnChange_fill_Kalender()"  >
			<?php
				foreach ($kelass as $kelas){
					$selected = $kelas_tahun_ajaran_id == $kelas["kelas_tahun_ajaran_id"] ? "selected" : "";				
					echo"<option value='$kelas[kelas_tahun_ajaran_id]' $selected>$kelas[kelas_name]</option>";
				}
			?>
		</select>
	</div>       
  
    <div>
    <?php 
		
		$this->widget('application.components.widgets.DateTextField', 
        array("name"=>"absent_date","id"=>"absent_date","value"=>$absent_date,"htmlOptions"=>"size='20' onchange='reloadPage();'", 
            "label"=>array("value"=>Yii::t("label","Start Date"),"htmlOptions"=>"class='form mandatory' style='width:100px' ")
        ));
		
    ?>
    </div>
    <div>
    <?php 
		
		$this->widget('application.components.widgets.DateTextField', 
        array("name"=>"absent_date_end","id"=>"absent_date_end","value"=>$absent_date_end,"htmlOptions"=>"size='20' onchange='reloadPage();'", 
            "label"=>array("value"=>Yii::t("label","End Date"),"htmlOptions"=>"class='form mandatory' style='width:100px' ")
        ));
		
    ?>
    </div>    
    <!--
    <div>
   		<label class="form mandatory" style="width:100px"><?php //echo Yii::t("label", "Absent Date Start") ?></label>	
		<input id="absent_date" name="absent_date" value= "<?php //echo $absent_date;?>" class="mtz-monthpicker-widgetcontainer" type="text" onchange="reloadPage();"></input>
    </div>
    <div>
   		<label class="form mandatory" style="width:100px"><?php //echo Yii::t("label", "Absent Date End") ?></label>	
		<input id="absent_date_end" name="absent_date_end" value= "<?php //echo $absent_date_end;?>" class="mtz-monthpicker-widgetcontainer" type="text" onchange="reloadPage();"></input>
    </div>    -->
                     	  
             
</div>
<div style="float:left; width:78%">    
	<table id="tblData"><tr></tr></table>
	<div id="navTblData"></div>
 </div>
  